package rhc.common.commons;

import org.apache.commons.lang3.StringUtils;

public class Host {

	private String hostName;
	private Integer port;
	public String getHostName() {
		return hostName;
	}
	public void setHostName(String hostName) {
		this.hostName = hostName;
	}
	public Integer getPort() {
		return port;
	}
	
	public void setPort(Integer port) {
		this.port = port;
	}
	
	public boolean equals(Object o){
		if(null == o){
			return false;
		}
		if(!(o instanceof Host)){
			return false;
		}
		Host h=(Host)o;
		String hHostName=h.getHostName();
		if(StringUtils.isEmpty(hostName) && StringUtils.isEmpty(hHostName)){
			return true;
		}else if(StringUtils.isEmpty(hostName) || StringUtils.isEmpty(hHostName)){
			return false;
		}else if(hostName.equals(hHostName)){
			Integer hPort=h.getPort();
			if(null == port && null == hPort){
				return true;
			}else if(null == port || null == hPort){
				return false;
			}else if(port == hPort){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
	
	public int hashCode(){
		int hCode=StringUtils.isEmpty(hostName)?0:hostName.hashCode();
		int pCode=null == port?0:port;
		return hCode+pCode;
	}
}
